import cv2

facer = cv2.CascadeClassifier("./haarcascades/haarcascade_frontalface_default.xml")
cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret, frame = cap.read()
    face = frame.copy()
    if ret:
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = facer.detectMultiScale(gray, 1.1, 5)
        for (x, y, w, h) in faces:
            ROI_img = frame[y:y + h, x:x + w]
            result = cv2.bilateralFilter(ROI_img, 9, 50, 50)
            frame[y:y + h, x:x + w] = result
        cv2.imshow('video', frame)
        cv2.imshow('face', face)
    key = cv2.waitKey(1)
    if key & 0xFF == ord('q'):
        break
cv2.destroyAllWindows()
